home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 22 / Cream of the Crop 22.iso / program / asm32.zip / E32.ZIP / LEFTRIGH.ASM < prev    next >
Assembly Source File  |  1994-12-29  |  5KB  |  272 lines

  1. ; LEFTRIGH.ASM for E32 - Copyright (C) 1994 Douglas Herr
  2. ;  all rights reserved
  3.  
  4. include    model.inc
  5.  
  6. public    left, right
  7. extrn    sh_left:near
  8. extrn    sh_right:near
  9. extrn    cursor_col:near
  10. extrn    up:near
  11. extrn    down:near
  12.  
  13. CR    equ    13
  14.  
  15. include    dataseg.inc
  16. extrn    cursor:dword
  17. extrn    left_margin:word, dirty_bits:byte
  18. extrn    save_column:byte, undo_length:byte
  19. extrn    filesiz:dword, cur_posn:word, display_mode:byte
  20.  
  21. home_proc    dd offset home_ascii
  22.         dd offset home_hex
  23. endd_proc    dd offset end_ascii
  24.         dd offset end_hex
  25. left_proc    dd offset left_ascii
  26.         dd offset left_hex
  27. right_proc    dd offset right_ascii
  28.         dd offset right_hex
  29.  
  30. @curseg    ends
  31.  
  32. include    codeseg.inc
  33. ;----------------------------------------------------------------------
  34. ;   These routines move the cursor left and right
  35. ;----------------------------------------------------------------------
  36. left    proc    near
  37.     movzx    edx,display_mode
  38.     jmp    left_proc[edx]
  39.  
  40. ;
  41. ; file is displayed in hex mode
  42. ;
  43. left_hex:
  44.     mov    esi,cursor
  45.     mov    dx,cur_posn
  46.     sub    esi,1
  47.     jc    short lr_no_change
  48.  
  49.     sub    dl,3
  50.     cmp    dl,10
  51.     jb    short move_up
  52.     mov    cur_posn,dx
  53.     mov    cursor,esi
  54.     ret
  55.  
  56. ;
  57. ; file is displayed in ASCII mode
  58. ;
  59. left_ascii:
  60.     cmp    cursor,0        ; at start of file?
  61.     jz    short lr_no_change    ; can't move left
  62.     mov    dx,cur_posn
  63.  
  64. left2:    test    dl,dl            ; at first screen column?
  65.     jne    short move_cursor_left
  66.     cmp    left_margin,0
  67.     jz    short move_up        ; if yes, move up one
  68.     call    sh_left            ; move window to show cursor
  69.     jmp    left2
  70.  
  71. move_cursor_left:
  72.     dec    cursor            ; shift the cursor offset
  73. lr_return:
  74.     call    cursor_col        ; compute column for cursor
  75.     mov    save_column,dl        ; save the cursor column
  76. lr_no_change:
  77.     mov    undo_length,0
  78.     clc
  79.     ret
  80.  
  81. move_up:
  82.     call    up            ; move up to next row
  83.     call    endd            ; and move to end of line
  84.     ret
  85. left    endp
  86.  
  87. ;
  88. ; advance cursor one byte in file
  89. ;
  90. right    proc    near
  91.     mov    esi,cursor
  92.     cmp    esi,filesiz        ; at the end of file?
  93.     je    short lr_no_change    ; if yes, can't move
  94.     movzx    eax,display_mode
  95.     jmp    right_proc[eax]
  96.  
  97. ;
  98. ; file displayed in hex mode
  99. ;
  100. right_hex:
  101.     inc    esi
  102.     cmp    esi,filesiz
  103.     jae    short lr_no_change
  104.     test    esi,0Fh            ; ZF = 1 if next line
  105.     jz    short move_down
  106.     mov    cursor,esi
  107.     and    esi,0Fh
  108.     mov    edx,esi
  109.     shl    edx,1
  110.     add    edx,esi
  111.     add    dl,10
  112.     mov    byte ptr cur_posn,dl
  113.     ret
  114.  
  115. ;
  116. ; file displayed in ASCII mode
  117. ;
  118. right_ascii:
  119.     push    es
  120.     push    fs
  121.     pop    es
  122.     cmp    byte ptr es:[esi],cr    ; at end of line?
  123.     pop    es
  124.     je    short move_down        ; if yes, then move down
  125.     inc    cursor            ; advance the cursor
  126.     jmp    lr_return
  127.  
  128. move_down:
  129.     call    home            ; move to start of line
  130.     call    down            ;    and move down one row
  131.     ret
  132. right    endp
  133.  
  134. @curseg    ends
  135.  
  136.  
  137. ; HOME
  138. ;
  139. ;  move the cursor to the start of the current line
  140. ;
  141. public    home
  142. extrn    find_start:near
  143. extrn    find_eol:near
  144.  
  145. include    codeseg.inc
  146.  
  147. home    proc    near
  148.  
  149.     movzx    esi,display_mode
  150.     jmp    home_proc[esi]
  151.  
  152. home_hex:
  153.     and    cursor,0ffffFFF0h
  154.     mov    byte ptr cur_posn,10
  155.     ret
  156.  
  157. home_ascii:
  158.     push    es
  159.     call    find_start        ; find start of line
  160.     mov    cursor,esi        ; save the new cursor
  161.     mov    save_column,0        ; save the cursor column
  162.     mov    byte ptr cur_posn,0    ; store column number
  163.     cmp    left_margin,0
  164.     je    short home_ret
  165.     mov    left_margin,0
  166.     or    dirty_bits,1        ; redraw screen if shift needed
  167.  
  168. home_ret:
  169.     clc
  170.     pop    es
  171.     ret
  172. home    endp
  173.  
  174.  
  175. ; ENDD
  176. ;
  177. ;  move the cursor to the end of the current line
  178. ;
  179.  
  180. public    endd
  181.  
  182. endd    proc    near
  183.     movzx    esi,display_mode
  184.     jmp    endd_proc[esi]
  185.  
  186. end_hex:
  187.     mov    esi,cursor
  188.     mov    dx,cur_posn
  189.     or    esi,0Fh            ; move to end of line
  190.     cmp    esi,filesiz        ; past end of file?
  191.     jb    short end_hex_cursor    ;  no, continue
  192.  
  193. ; limit offset to last character in file
  194.     mov    esi,filesiz
  195.     dec    esi
  196.  
  197. ; save offset & calculate cursor position
  198. end_hex_cursor:
  199.     mov    cursor,esi
  200.     and    esi,0Fh
  201.     mov    edx,esi
  202.     shl    esi,1
  203.     add    edx,esi
  204.     add    dl,10
  205.     mov    byte ptr cur_posn,dl
  206.     ret
  207.  
  208. end_ascii:
  209.     mov    esi,cursor
  210.     call    find_eol        ; find the end of this line
  211.     mov    cursor,esi        ; store the new cursor
  212.     call    cursor_col        ; compute the correct column
  213.     mov    save_column,dl        ; save the cursor column
  214.     ret
  215. endd    endp
  216.  
  217. @curseg    ends
  218.  
  219.  
  220.  
  221. ; SHIFT_RIGHT
  222. ;
  223. ;  This subroutine adjusts the cursor position ahead to
  224. ;  the saved cursor column.  On entry DH has the cursor row.
  225. ;
  226.  
  227. public    shift_right
  228.  
  229. include    codeseg.inc
  230. shift_right    proc    near
  231.     movzx    cx,save_column
  232.     mov    bp,cx
  233.     add    cx,left_margin
  234.     xor    dl,dl
  235.     mov    cur_posn,dx    ; get cursor row/col
  236.     jcxz    no_change
  237.     push    fs
  238.     pop    es
  239. right_again:
  240.     push    ecx
  241.     cmp    esi,filesiz
  242.     jae    short dont_move
  243.     cmp    byte ptr es:[esi],CR    ; at end of line?
  244.     je    short dont_move
  245.     call    right
  246. dont_move:
  247.     pop    ecx
  248.     movzx    ax,save_column
  249.     cmp    ax,cx        ; is cursor still in margin?
  250.     jl    short in_margin    ; yup, keep moving
  251.     mov    dx,cur_posn
  252.     xor    dh,dh
  253.     cmp    dx,bp            ; at saved cursor position?
  254.     je    short right_done    ; if yes, we're done
  255.     ja    short right_too_far    ; did we go too far?
  256. in_margin:
  257.     loop    right_again
  258. right_done:
  259.     mov    cx,bp
  260.     mov    save_column,cl    ; get back saved cursor position
  261. no_change:
  262.     ret
  263.  
  264. right_too_far:
  265.     call    left        ; move back left one place
  266.     jmp    right_done
  267.  
  268. shift_right    endp
  269.  
  270. @curseg    ends
  271.     end
  272.